package com.xxz.course;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class FirstActivity extends AppCompatActivity implements View.OnClickListener {
    TextView out;
    EditText edit1,edit2;
    Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        out =findViewById(R.id.txtout);
        edit1=findViewById(R.id.inp1);
        edit2=findViewById(R.id.inp2);
        btn = findViewById(R.id.btn);
        btn.setOnClickListener(this);


    }
    @Override
    public void onClick(View v) {
        Log.i("main","onClick msg....");
        String str1 = edit1.getText().toString();
        String str2 = edit2.getText().toString();
        float he;
        he = Float.parseFloat(str1);
        //float he1=(float)(Math.round(he*100))/100;
        float we;
        we = Float.parseFloat(str2);
        //float we1=(float)(Math.round(we*100))/100;
        float bmi;
        bmi=(we)/(he*he);
        float bmi1=(float)(Math.round(bmi*100))/100;
        if(bmi1<18.5)
        {
            out.setText("您的BMI为"+bmi1+"\n"+"这低于正常水平，您需要注意日常营养摄入，合理增加体重");

        }
        else if(bmi1>=18.5 && bmi<24.0)
        {
            out.setText("您的BMI为"+bmi1+"\n"+"这属于正常水平，您只需要保持正常生活节奏");

        }
        else if(bmi1>=24.0 && bmi1<28)
        {
            out.setText("您的BMI为"+bmi1+"\n"+"这属于超重水平，您需要减少脂肪等摄入，注意保持体重正常");

        }
        else
        {
            out.setText("您的BMI为"+bmi1+"\n"+"这属于肥胖水平，您需要时刻关注体重情况，注意饮食，减少热量摄入，开始减肥");
        }
    }
}